<template>
  <el-form :model="outline" ref="outline" label-width="50px" class="demo-dynamic">
    <!-- 大纲下的目录 -->
    <el-form-item
      v-for="(catalog, index) in outline.catalogs"
      :label="'目录' + (index+1)"
      :key="catalog.key"
      :prop="'catalogs.' + index + '.value'">
      <el-input v-model="catalog.value" style="width: 200px" size="mini"></el-input>
      <el-button @click.prevent="removeCatalog(catalog)" size="mini" type="danger">删除目录</el-button>

      <!-- 目录下的课件 -->
      <el-form :model="catalog" ref="catalog" label-width="50px" class="demo-dynamic">
        <el-form-item 
          v-for="(classFile, index) in catalog.classFiles"
          :label="'课程' + (index+1)"
          :key="classFile.key"
          :prop="'classFiles.' + index + '.value'">
          <el-input v-model="classFile.value" style="width: 150px" size="mini"></el-input>
          <el-button @click.prevent="removeClassFile(catalog, classFile)" size="mini" type="danger">删除课程</el-button>
        </el-form-item>
      <el-button @click="addClassFile(catalog)" size="mini">新增课程</el-button>
      </el-form>

    </el-form-item>
    <el-form-item>
      <el-button @click="addCatalog" size="mini">新增目录</el-button>
      <el-button type="primary" @click="submitForm('dynamicValidateForm')" size="mini">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { Message } from 'element-ui'

  export default {
    data() {
      return {
        //大纲数据
        outline: {
          catalogs: [{
            classFiles: [{
              value: ''
            }],
            catalog: ''
          }]
        },
        outline: {
          catalogs: [{
            classFileList: [{
              classTitle: '',
              outlineId: 0,
              classFile: ''
            }],
            catalogName: ''
          }]
        },
      };
    },
    methods: {
      //目录新增删除
      removeCatalog(item) {
        var index = this.outline.catalogs.indexOf(item)
        if (index !== -1) {
          this.outline.catalogs.splice(index, 1)
        }
      },
      addCatalog() {
        this.outline.catalogs.push({
          classFiles: [{
              value: ''
            }],
            catalog: '',
          key: Date.now()
        });
      },

      //课程新增删除
      removeClassFile(catalog, classFile) {
        var index = catalog.classFiles.indexOf(classFile)
        if (index !== -1) {
          catalog.classFiles.splice(index, 1)
        }
      },
      addClassFile(catalog) {
        catalog.classFiles.push({
          value: '',
          key: Date.now()
        });
      }
    }
  }
</script>